#ifndef HB_PX4_FLIGHT_HANDLER_H
#define HB_PX4_FLIGHT_HANDLER_H

#include <iostream>
#include <fstream>
#include <chrono>
#include <algorithm>
#include <unistd.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <string.h>
#include <map>
#include <mutex>
#include <vector>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/statfs.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <math.h>
#include <thread>
#include <sys/types.h>
#include <dirent.h>
//mavlink header file
#include  <common/mavlink.h>
#include  <minimal/mavlink.h>
#include  <standard/mavlink.h>

#include <opencv2/opencv.hpp>


int64_t getTimeMillis();

void sleepMs(uint32_t timeMs);

double wrap360(const double angle);

double wrap180(const double angle);

class px4FlightHandler
{
public:
	px4FlightHandler();

	~px4FlightHandler();

	bool startUpSystem(const char *connectType);

	bool startUdpConnect();

	bool startUartConnect();

	bool udpClient(const char *ip, const char *port);

	void subcribeMavlinkMessages();


	//log
	bool getLogDir();

	bool createLogFile();

	bool writeLogFile(const char * format, ...);

	void recodeCpuTemperature();

	void fflushLogFile();

private:
	bool m_connect;
	mavlink_status_t m_mavlinkStatus;

	int m_systemId;
	int m_compid;

	//udp connect
	bool m_udpConnectFlag;
	int m_udpSockfd;
	struct sockaddr_in m_saddr;

	//uart connect
	bool m_uartConnectFlag;



	//log file
	FILE *m_logFp;
	bool m_getLogDirFlag;
	uint32_t m_lastLogNum;
};


extern px4FlightHandler flightHandler;

#endif
